<?php
namespace app\api\model;
use think\Model;

class Insure extends Model{  
    public function allList($filter = null){
        $where = [];
        $page = 1;
        $pageCount = 10;
        if(!empty($filter)){
            //指定id查询
            if(!empty($filter['id'])){
                $where['id'] = $filter['id'];
            }
            //模糊查询           
            if(!empty($filter['keyword'])){
                $where['insure_name|insure_code'] = ['like',"%{$filter['keyword']}%"];               
            }      
            //页码            
            $page = !empty($filter['page']) ? $filter['page'] : $page;
            $pageCount = !empty($filter['page_count']) ? $filter['page_count'] : $pageCount;     
        }
        $datas = $this->where($where)->page("$page,$pageCount")->order('id', 'desc')->select(); 
        $dataCount = $this->where($where)->count(); 
        $datalist = array(
            'datas' => $datas,            
            'dataCount' => $dataCount
        );
        return $datalist;
    }
}